/**
 * 工具函数
 */
console.log("工具函数");

require("../../fonts/iconfont.css")

// 手机号码验证
function phoneCheck(num) {
    return /^1[3-9]\d{9}$/.test(num)
}
// 密码验证
function passwordCheck(pwd) {
    return /^[a-zA-Z]\w{5,17}$/.test(pwd);
}/*
功能：信息提示框
参数：
    icon: 字体图标的类名
    msg: 提示信息
 */
function toast(icon = "zp-close", msg = "操作成功") {

    const msgDiv = document.createElement("div");
    msgDiv.className = "toast";
    msgDiv.innerHTML = `
    <span class="rotate90"> <i class="iconfont  ${icon}"></i></span>
    <p class="mt8">${msg}</p>
    `;
    document.body.append(msgDiv);
    // 自动消失
    window.setTimeout(() => {
        msgDiv.remove()
    }, 3000)
}

function showFooterNav(pageflag) {
    /*
    pageflag的值
        index
        mine
        run 
     */
    //1 创建标签
    const navDiv = document.createElement("div");
    //2 设置样式
    navDiv.className = "footer-nav dpflex";
    //3 添加内容

    navDiv.innerHTML = `
        <a class="nav-link  ${pageflag === "index" ? "active" : ""}" href="./index.html">
          <i class="iconfont zp-home icon"></i>
          <p>首页</p>
        </a>
        <a class="nav-link  ${pageflag === "run" ? "active" : ""}" href="./run.html">
           <i class="iconfont zp-exercise icon"></i>
           <p>运动</p>
        </a>
        <a class="nav-link  ${pageflag === "mine" ? "active" : ""}" href="./mine.html">
           <i class="iconfont zp-personal icon"></i>
           <p>我的</p>
        </a>
        
      `;


    //4 添加到页面
    document.querySelector("#footer").append(navDiv)


}


//服务器地址
const BASE_URL = "http://139.9.177.51:3701"
// 挂在window对象身上
window.$util = {
    phoneCheck,
    passwordCheck,
    BASE_URL,
    toast,
    showFooterNav,
}